﻿
// 项目展示地址:"http://www.ddxc.org/"
// 如果你有什么好的建议或者觉得可以加什么功能，请加QQ群：104390185大家交流沟通
// 项目展示地址:"http://www.yoyocms.com/"
//博客地址：http://www.cnblogs.com/wer-ltm/
//代码生成器帮助文档：http://www.cnblogs.com/wer-ltm/p/5777190.html
// <Author-作者>角落的白板笔</Author-作者>
// Copyright © YoYoCms@中国.2017-11-29T09:55:47. All Rights Reserved.
//<生成时间>2017-11-29T09:55:47</生成时间>
using Abp.Application.Services.Dto;
using Abp.Web.Models;
using Abp.Web.Mvc.Authorization;
using KDS.Mes.Authorization;
using KDS.Mes.Mes.Lines;
using KDS.Mes.Mes.Lines.Dtos;
using KDS.Mes.Mes.StopEquipments;
using KDS.Mes.Mes.StopEquipments.Dtos;

using KDS.Mes.Web.Controllers;
using KDS.Mes.Web.Models.StopEquipment;
using KDS.Mes.Web.Models.StopEquipments;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace KDS.Mes.Web.Areas.Mpa.Controllers
{
    public class StopEquipmentsController : MesControllerBase
    {

        private readonly IStopEquipmentAppService _stopEquipmentAppService;
        private readonly ILineAppService _lineAppService;

        public StopEquipmentsController(IStopEquipmentAppService stopEquipmentAppService)
        {
            _stopEquipmentAppService = stopEquipmentAppService;
           

    }

        public async Task<ActionResult> Index()
        {
           
            var lines = new List<ComboboxItemDto>();

            lines.Insert(0, new ComboboxItemDto("", ""));
            lines.Insert(1, new ComboboxItemDto("0", "未上线"));
            lines.Insert(2, new ComboboxItemDto("1", "已上线"));

            // var cartypes = new List<ComboboxItemDto>();
            //var getCartypesOutput = await _cartypeAppService.GetCartypes(new GetCartypeInput());
            //cartypes = getCartypesOutput.Items.Select(r => new ComboboxItemDto(r.Id.ToString(), r.CartypeName)).ToList();

            //var styles = new List<ComboboxItemDto>();
            //var getStylesOutput = await _styleAppService.Getstyles(new GetStyleInput());
            //styles = getStylesOutput.Items.Select(r => new ComboboxItemDto(r.Id.ToString(), r.StyleName)).ToList();

            //var seatPositions = new List<ComboboxItemDto>();
            //var getSeatPositionOutput = await _seatPositionAppService.GetSeatPositions(new GetSeatPositionInput());
            //seatPositions = getSeatPositionOutput.Items.Select(r => new ComboboxItemDto(r.Id.ToString(), r.SeatPositionName)).ToList();

            //cartypes.Insert(0, new ComboboxItemDto("", ""));
            //styles.Insert(0, new ComboboxItemDto("", ""));
            //seatPositions.Insert(0, new ComboboxItemDto("", ""));
            var model = new StopEquipmentsViewModel
            {
                FilterText = Request.QueryString["filterText"],
                Lines = lines,
              

            };
           

            return View(model);
          
            //var model = new GetPartInput {FilterText = Request.QueryString["filterText"]};
            //return View();
        }

        [DontWrapResult]
        public JsonResult GetAllStopEquipments(int limit, int offset, string sortfiled, string sortway, DateTime? time1, DateTime? time2
                                       )
        {
            var sort = !string.IsNullOrEmpty(sortfiled) ? string.Format("{0} {1}", sortfiled, sortway) : "";
            var filter = new GetStopEquipmentInput
            {
                SkipCount = offset,
                MaxResultCount = limit,
                Sorting = sort,
                Time1=time1,
                Time2=time2

            };
            var pagedTasks = _stopEquipmentAppService.GetPagedStopEquipments(filter);
            var j = Json(new { total = pagedTasks.TotalCount, rows = pagedTasks.Items }, JsonRequestBehavior.AllowGet);
            return Json(new { total = pagedTasks.TotalCount, rows = pagedTasks.Items }, JsonRequestBehavior.AllowGet);

        }
        /// <summary>
        /// 根据id获取进行编辑或者添加的用户信息
        /// </summary>
        /// <param name="id"></param>
        [AbpMvcAuthorize(AppPermissions.Pages_StopEquipment_CreateStopEquipment, AppPermissions.Pages_StopEquipment_EditStopEquipment)]
        public async Task<PartialViewResult> CreateOrEditStopEquipmentModal(int? id)
        {
            var input = new NullableIdDto<int> { Id = id };

            var output = await _stopEquipmentAppService.GetStopEquipmentForEditAsync(input);

            var viewModel = new CreateOrEditStopEquipmentModalViewModel(output);


            return PartialView("_CreateOrEditStopEquipmentModal", viewModel);
        }

        
     
	 
       
    }
}